package view.listener;

import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;

import view.views.CSADView;
import controller.data.ReadDocumentationRevision;

public class InfoListener implements Listener {

	private final CSADView view;
	private final int i;
	private final ToolBar toolbar;
	private final Shell shell;

	public InfoListener(CSADView view, ToolBar toolbar, Shell shell, int i) {
		this.view = view;
		this.toolbar = toolbar;
		this.shell = shell;
		this.i = i;
	}

	public void handleEvent(Event event) {
		// TODO Auto-generated method stub
		ToolItem item = (ToolItem) event.widget;
		if (i == -1) {
			view
					.showPopUpInfo(item, view.toolbarDoku, shell,
							"" + " " + "", "");
		} else {
			ReadDocumentationRevision revision = view.listOfData.get(i)
					.getRevision();
			StringBuilder buildAuthor = new StringBuilder();
			buildAuthor.append(revision.getFirstname()).append(" ");
			buildAuthor.append(revision.getLastname());
			view.showPopUpInfo(item, toolbar, shell, buildAuthor.toString(),
					revision.getDate());
		}
	}
}
